import request from '@/utils/request'
import type {
  Booking,
  CreateBookingRequest,
  UpdateBookingRequest,
  BookingListResponse,
  CourseSchedule
} from '@/types/api/booking'
import type { BaseResponse, PaginationResponse } from '@/types/common/response'

/**
 * 课程预约管理相关API
 */
export const bookingApi = {
  /**
   * 获取课程预约列表
   * @param params 查询参数
   */
  getBookingList(params: { page: number; pageSize: number; keyword?: string; status?: number }) {
    return request.get<BaseResponse<PaginationResponse<Booking>>>('/bookings', { params })
  },

  /**
   * 获取课程预约详情
   * @param id 预约ID
   */
  getBookingDetail(id: number) {
    return request.get<BaseResponse<Booking>>(`/bookings/${id}`)
  },

  /**
   * 创建课程预约
   * @param data 预约信息
   */
  createBooking(data: CreateBookingRequest) {
    return request.post<BaseResponse<null>>('/bookings', data)
  },

  /**
   * 更新课程预约
   * @param id 预约ID
   * @param data 预约信息
   */
  updateBooking(id: number, data: UpdateBookingRequest) {
    return request.put<BaseResponse<null>>(`/bookings/${id}`, data)
  },

  /**
   * 删除课程预约
   * @param id 预约ID
   */
  deleteBooking(id: number) {
    return request.delete<BaseResponse<null>>(`/bookings/${id}`)
  },

  /**
   * 获取课程时间安排列表
   * @param params 查询参数
   */
  getCourseSchedules(params: { date?: string; courseId?: number; coachId?: number }) {
    return request.get<BaseResponse<CourseSchedule[]>>('/course-schedules', { params })
  },

  /**
   * 确认预约
   * @param id 预约ID
   */
  confirmBooking(id: number) {
    return request.put<BaseResponse<null>>(`/bookings/${id}/confirm`)
  },

  /**
   * 取消预约
   * @param id 预约ID
   */
  cancelBooking(id: number) {
    return request.put<BaseResponse<null>>(`/bookings/${id}/cancel`)
  }
}
